#include"process.h"
#include<string.h>
#include<unistd.h>
#include<stdio.h>

#define SIZE 101
#define STYLE '='
void FlushProcess(double total,double curr)// 更新进度, 按照下载进度，进行更新进度条
{
	if(curr>total)
		curr=total;
	double rate=curr/total*100;//按照进度格式
	int cnt=(int)rate;//强转为整型方便计数
	static const char *lable="|/-\\";
	static int index=0;
	 int len=strlen(lable);
	char processbuff[SIZE];
	memset(processbuff,'\0',sizeof(processbuff));
	int i=0;
	for(;i<cnt;i++)
	{
		processbuff[i]=STYLE;
	}
	printf("[%-100s][%.1lf%%][%c]\r",processbuff,rate,lable[index++]);
	index%=len;
	fflush(stdout);
	if(cnt>=100)
	{
		printf("\n");
	}

}
	
//version1:实际场景不适用
void Process()
{
	const char *lable="|/-\\";
	int len=strlen(lable);
	char processbuff[SIZE];
	memset (processbuff,'\0',sizeof(processbuff));
	int cnt=0;
	while(cnt!=101)
	{
		printf("[%-100s][%d%%][%c]\r",processbuff,cnt,lable[cnt%len]);
		fflush(stdout);
		processbuff[cnt++]=STYLE;
		usleep(30000);
	}
	printf("\n");
}
